<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\index\service;

/**
 * Description of Group
 *
 * @author Dongasai
 */
class Group
{

    /**
     * 获取id 列表
     * @param type $uid
     */
    public static function idList($uid)
    {
        $groupModel = \think\Loader::model('group');
        $where      = [
            'user_id' => $uid
        ];
        return $groupModel->where($where)->column('id');
    }

    /**
     * 列表
     */
    public static function lists($where, $order, $page, $low = 10)
    {
        $groupModel = \think\Loader::model('group');

        $list  = $groupModel->where($where)->order($order)->page($page, $low)->select();
        $count = $groupModel->where($where)->count();
        if ($count === false) {
            return false;
        } else {
            return ['totle' => $count, 'list' => $list];
        }
    }

    /**
     * 增加分组
     * @param type $uid 用户id
     * @param type $name 分组名字
     */
    public static function add($uid, $name)
    {
        if (empty($uid) || empty($name)) {
            return '数据格式错误!';
        }
        $data = [
            'user_id' => $uid,
            'name'    => $name
        ];

        $groupModel = \think\Loader::model('group');
        $re         = $groupModel->data($data)->save();
        if ($re) {
            return true;
        } else {
            return '增加数据出错!';
        }
    }

    /**
     * 分组信息
     * @param type $group_id
     */
    public static function info($group_id)
    {
        $groupModel = \think\Loader::model('group');
        $info       = $groupModel->get(['id' => $group_id]);
        if ($info) {
            return $info;
        }
    }

}
